//
//  LCFTabBarController.m
//  lcf-newproject
//
//  Created by yangyang on 14-11-11.
//  Copyright (c) 2014年 yang. All rights reserved.
//

#import "LCFTabBarController.h"
#import "LCFRootViewController.h"

#define IndexViewContoller @"IndexViewController"
#define ProjectViewController @"ProjectViewController"
#define EarningViewController @"EarningViewController"
#define MineViewController @"MineViewController"

#define IndexTitle @"理财范"
#define ProjectTitle @"担保项目"
#define EarningTitle @"收益日历"
#define MineTitle @"我的"

#define LCFTabBar @"LCFViewControllers"

@implementation LCFTabBarController

-(void)viewDidLoad{
    [super viewDidLoad];
    self.tabBar.hidden = YES;
    [self createControllers];
    [self createCustomTabBar];
    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"123.png"] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.translucent = YES;


}

//将视图控制器添加到标签栏中
-(void)createControllers{
    NSArray * controllersName = @[IndexViewContoller,ProjectViewController,EarningViewController,MineViewController];
    NSArray * controllersTitle = @[IndexTitle,ProjectTitle,EarningTitle,MineTitle];
    NSMutableArray * controllers = [[NSMutableArray alloc]init];
    for (int i = 0; i<controllersName.count; i++) {
        NSString * className = [controllersName objectAtIndex:i];
        NSString * classTitle = [controllersTitle objectAtIndex:i];
        Class class = NSClassFromString(className);
        LCFRootViewController * viewController = [[class alloc]init];
        UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:viewController];
        UILabel * titleLabel = [LCFUIGlobel createLabelWithTitle:classTitle withFrame:LCFTitleFrame withFontType:nil withFontSize:LCFTitleSize withFontColor:[UIColor whiteColor] isNeedBold:YES];
        viewController.navigationItem.titleView = titleLabel;
        [controllers addObject:nav];
    }
    self.viewControllers = controllers;
}

//根据plist文件创建标签栏
-(void)createCustomTabBar{
    
    NSString * path = [[NSBundle mainBundle]pathForResource:LCFTabBar ofType:@"plist"];
    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];
    AppDelegate *delegate = [[UIApplication sharedApplication]delegate];
    _custom = delegate.CustomTabBarViewController;
    [_custom createTabBarWithFrame:CGRectMake(0, __MainScreen_Height-__TabBar_Height, __MainScreen_Width, __TabBar_Height) tabBarDic:dict];
//    _custom = [[CustomTabBar alloc]initWithFrame:CGRectMake(0, __MainScreen_Height-__TabBar_Height, __MainScreen_Width, __TabBar_Height) tabBarDic:dict];
        _custom.delegate = self;
    [self.view addSubview:_custom];

}


#pragma mark - CustomTabBarDelegate
-(void)customTabBar:(CustomTabBar *)custom didSelectedIndex:(NSInteger)index{
    //实现视图切换
    self.selectedIndex = index;
    //点击tabbar后回到初始界面
    //[self createControllers];
}
@end
